home *** CD-ROM | disk | FTP | other *** search
/ Ultra Pack / UltraComputing Partner Applications.iso / SunLabs / tclTK / src / tk4.0 / tests / option.test < prev    next >
Text File  |  1994-12-17  |  11KB  |  212 lines

  1. # This file is a Tcl script to test out the option-handling facilities
  2. # of Tk.  It is organized in the standard fashion for Tcl tests.
  3. #
  4. # Copyright (c) 1991-1993 The Regents of the University of California.
  5. # Copyright (c) 1994 Sun Microsystems, Inc.
  6. #
  7. # See the file "license.terms" for information on usage and redistribution
  8. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  9. #
  10. # @(#) option.test 1.13 94/12/17 15:54:33
  11.  
  12. if {[string compare test [info procs test]] == 1} then \
  13.   {source defs}
  14.  
  15. catch {destroy .op1}
  16. catch {destroy .op2}
  17. set appName [winfo name .]
  18.  
  19. # First, test basic retrievals, being sure to trigger all the various
  20. # types of NodeElements (EXACT_LEAF_NAME, WILDCARD_NODE_CLASS, and
  21. # everything in-between).
  22.  
  23. frame .op1 -class Class1
  24. frame .op2 -class Class2
  25. frame .op1.op3 -class Class1
  26. frame .op1.op4 -class Class3
  27. frame .op2.op5 -class Class2
  28. frame .op1.op3.op6 -class Class4
  29.  
  30. option clear
  31. option add *Color1 red
  32. option add *x blue
  33. option add *Class1.x yellow
  34. option add $appName.op1.x green
  35. option add *Class2.Color1 orange
  36. option add $appName.op2.op5.Color2 purple
  37. option add $appName.Class1.Class3.y brown
  38. option add $appName*op6*Color2 black
  39. option add $appName*Class1.op1.Color2 grey
  40.  
  41. test option-1.1 {basic option retrieval} {option get . x Color1} blue
  42. test option-1.2 {basic option retrieval} {option get . y Color1} red
  43. test option-1.3 {basic option retrieval} {option get . z Color1} red
  44. test option-1.4 {basic option retrieval} {option get . x Color2} blue
  45. test option-1.5 {basic option retrieval} {option get . y Color2} {}
  46. test option-1.6 {basic option retrieval} {option get . z Color2} {}
  47.  
  48. test option-2.1 {basic option retrieval} {option get .op1 x Color1} green
  49. test option-2.2 {basic option retrieval} {option get .op1 y Color1} red
  50. test option-2.3 {basic option retrieval} {option get .op1 z Color1} red
  51. test option-2.4 {basic option retrieval} {option get .op1 x Color2} green
  52. test option-2.5 {basic option retrieval} {option get .op1 y Color2} {}
  53. test option-2.6 {basic option retrieval} {option get .op1 z Color2} {}
  54.  
  55. test option-3.1 {basic option retrieval} {option get .op1.op3 x Color1} yellow
  56. test option-3.2 {basic option retrieval} {option get .op1.op3 y Color1} red
  57. test option-3.3 {basic option retrieval} {option get .op1.op3 z Color1} red
  58. test option-3.4 {basic option retrieval} {option get .op1.op3 x Color2} yellow
  59. test option-3.5 {basic option retrieval} {option get .op1.op3 y Color2} {}
  60. test option-3.6 {basic option retrieval} {option get .op1.op3 z Color2} {}
  61.  
  62. test option-4.1 {basic option retrieval} {option get .op1.op3.op6 x Color1} blue
  63. test option-4.2 {basic option retrieval} {option get .op1.op3.op6 y Color1} red
  64. test option-4.3 {basic option retrieval} {option get .op1.op3.op6 z Color1} red
  65. test option-4.4 {basic option retrieval} {option get .op1.op3.op6 x Color2} black
  66. test option-4.5 {basic option retrieval} {option get .op1.op3.op6 y Color2} black
  67. test option-4.6 {basic option retrieval} {option get .op1.op3.op6 z Color2} black
  68.  
  69. test option-5.1 {basic option retrieval} {option get .op1.op4 x Color1} blue
  70. test option-5.2 {basic option retrieval} {option get .op1.op4 y Color1} brown
  71. test option-5.3 {basic option retrieval} {option get .op1.op4 z Color1} red
  72. test option-5.4 {basic option retrieval} {option get .op1.op4 x Color2} blue
  73. test option-5.5 {basic option retrieval} {option get .op1.op4 y Color2} brown
  74. test option-5.6 {basic option retrieval} {option get .op1.op4 z Color2} {}
  75.  
  76. test option-6.1 {basic option retrieval} {option get .op2 x Color1} orange
  77. test option-6.2 {basic option retrieval} {option get .op2 y Color1} orange
  78. test option-6.3 {basic option retrieval} {option get .op2 z Color1} orange
  79. test option-6.4 {basic option retrieval} {option get .op2 x Color2} blue
  80. test option-6.5 {basic option retrieval} {option get .op2 y Color2} {}
  81. test option-6.6 {basic option retrieval} {option get .op2 z Color2} {}
  82.  
  83. test option-7.1 {basic option retrieval} {option get .op2.op5 x Color1} orange
  84. test option-7.2 {basic option retrieval} {option get .op2.op5 y Color1} orange
  85. test option-7.3 {basic option retrieval} {option get .op2.op5 z Color1} orange
  86. test option-7.4 {basic option retrieval} {option get .op2.op5 x Color2} purple
  87. test option-7.5 {basic option retrieval} {option get .op2.op5 y Color2} purple
  88. test option-7.6 {basic option retrieval} {option get .op2.op5 z Color2} purple
  89.  
  90. # Now try similar tests to above, except jump around non-hierarchically
  91. # between windows to make sure that the option stacks are pushed and
  92. # popped correctly.
  93.  
  94. option get . foo Foo
  95. test option-8.1 {stack pushing/popping} {option get .op2.op5 x Color1} orange
  96. test option-8.2 {stack pushing/popping} {option get .op2.op5 y Color1} orange
  97. test option-8.3 {stack pushing/popping} {option get .op2.op5 z Color1} orange
  98. test option-8.4 {stack pushing/popping} {option get .op2.op5 x Color2} purple
  99. test option-8.5 {stack pushing/popping} {option get .op2.op5 y Color2} purple
  100. test option-8.6 {stack pushing/popping} {option get .op2.op5 z Color2} purple
  101.  
  102. test option-9.1 {stack pushing/popping} {option get . x Color1} blue
  103. test option-9.2 {stack pushing/popping} {option get . y Color1} red
  104. test option-9.3 {stack pushing/popping} {option get . z Color1} red
  105. test option-9.4 {stack pushing/popping} {option get . x Color2} blue
  106. test option-9.5 {stack pushing/popping} {option get . y Color2} {}
  107. test option-9.6 {stack pushing/popping} {option get . z Color2} {}
  108.  
  109. test option-10.1 {stack pushing/popping} {option get .op1.op3.op6 x Color1} blue
  110. test option-10.2 {stack pushing/popping} {option get .op1.op3.op6 y Color1} red
  111. test option-10.3 {stack pushing/popping} {option get .op1.op3.op6 z Color1} red
  112. test option-10.4 {stack pushing/popping} {option get .op1.op3.op6 x Color2} black
  113. test option-10.5 {stack pushing/popping} {option get .op1.op3.op6 y Color2} black
  114. test option-10.6 {stack pushing/popping} {option get .op1.op3.op6 z Color2} black
  115.  
  116. test option-11.1 {stack pushing/popping} {option get .op1.op3 x Color1} yellow
  117. test option-11.2 {stack pushing/popping} {option get .op1.op3 y Color1} red
  118. test option-11.3 {stack pushing/popping} {option get .op1.op3 z Color1} red
  119. test option-11.4 {stack pushing/popping} {option get .op1.op3 x Color2} yellow
  120. test option-11.5 {stack pushing/popping} {option get .op1.op3 y Color2} {}
  121. test option-11.6 {stack pushing/popping} {option get .op1.op3 z Color2} {}
  122.  
  123. test option-12.1 {stack pushing/popping} {option get .op1 x Color1} green
  124. test option-12.2 {stack pushing/popping} {option get .op1 y Color1} red
  125. test option-12.3 {stack pushing/popping} {option get .op1 z Color1} red
  126. test option-12.4 {stack pushing/popping} {option get .op1 x Color2} green
  127. test option-12.5 {stack pushing/popping} {option get .op1 y Color2} {}
  128. test option-12.6 {stack pushing/popping} {option get .op1 z Color2} {}
  129.  
  130. # Test the major priority levels (widgetDefault, etc.)
  131.  
  132. option add $appName.op1.a 100 100
  133. option add $appName.op1.A interactive interactive
  134. option add $appName.op1.b userDefault userDefault
  135. option add $appName.op1.B startupFile startupFile
  136. option add $appName.op1.c widgetDefault widgetDefault
  137. option add $appName.op1.C 0 0
  138.  
  139. test option-13.1 {priority levels} {option get .op1 a A} 100
  140. test option-13.2 {priority levels} {option get .op1 b A} interactive
  141. test option-13.3 {priority levels} {option get .op1 b B} userDefault
  142. test option-13.4 {priority levels} {option get .op1 c B} startupFile
  143. test option-13.5 {priority levels} {option get .op1 c C} widgetDefault
  144. option add $appName.op1.B file2 widget
  145. test option-13.7 {priority levels} {option get .op1 c B} startupFile
  146. option add $appName.op1.B file2 startupFile
  147. test option-13.8 {priority levels} {option get .op1 c B} file2
  148.  
  149. # Test various error conditions
  150.  
  151. test option-14.1 {error conditions} {
  152.     list [catch {option} msg] $msg
  153. } {1 {wrong # args: should be "option cmd arg ?arg ...?"}}
  154. test option-14.2 {error conditions} {
  155.     list [catch {option x} msg] $msg
  156. } {1 {bad option "x": must be add, clear, get, or readfile}}
  157. test option-14.3 {error conditions} {
  158.     list [catch {option foo 3} msg] $msg
  159. } {1 {bad option "foo": must be add, clear, get, or readfile}}
  160. test option-14.4 {error conditions} {
  161.     list [catch {option add 3} msg] $msg
  162. } {1 {wrong # args: should be "option add pattern value ?priority?"}}
  163. test option-14.5 {error conditions} {
  164.     list [catch {option add . a b c} msg] $msg
  165. } {1 {wrong # args: should be "option add pattern value ?priority?"}}
  166. test option-14.6 {error conditions} {
  167.     list [catch {option add . a -1} msg] $msg
  168. } {1 {bad priority level "-1": must be widgetDefault, startupFile, userDefault, interactive, or a number between 0 and 100}}
  169. test option-14.7 {error conditions} {
  170.     list [catch {option add . a 101} msg] $msg
  171. } {1 {bad priority level "101": must be widgetDefault, startupFile, userDefault, interactive, or a number between 0 and 100}}
  172. test option-14.8 {error conditions} {
  173.     list [catch {option add . a gorp} msg] $msg
  174. } {1 {bad priority level "gorp": must be widgetDefault, startupFile, userDefault, interactive, or a number between 0 and 100}}
  175. test option-14.9 {error conditions} {
  176.     list [catch {option get 3} msg] $msg
  177. } {1 {wrong # args: should be "option get window name class"}}
  178. test option-14.10 {error conditions} {
  179.     list [catch {option get 3 4} msg] $msg
  180. } {1 {wrong # args: should be "option get window name class"}}
  181. test option-14.11 {error conditions} {
  182.     list [catch {option get 3 4 5 6} msg] $msg
  183. } {1 {wrong # args: should be "option get window name class"}}
  184. test option-14.12 {error conditions} {
  185.     list [catch {option get .gorp.gorp a A} msg] $msg
  186. } {1 {bad window path name ".gorp.gorp"}}
  187.  
  188. test option-15.1 {database files} {
  189.     list [catch {option read non-existent} msg] $msg
  190. } {1 {couldn't read file "non-existent"}}
  191. option read option.file1
  192. test option-15.2 {database files} {option get . x1 color} blue
  193. if {$appName == "tktest"} {
  194.     test option-15.3 {database files} {option get . x2 color} green
  195. }
  196. test option-15.4 {database files} {option get . x3 color} purple
  197. test option-15.5 {database files} {option get . {x 4} color} brown
  198. test option-15.5 {database files} {option get . x6 color} {}
  199. test option-15.7 {database files} {
  200.     list [catch {option read option.file1 widget foo} msg] $msg
  201. } {1 {wrong # args:  should be "option readfile fileName ?priority?"}}
  202. option add *x3 burgundy
  203. catch {option read option.file1 userDefault}
  204. test option-15.8 {database files} {option get . x3 color} burgundy
  205. test option-15.9 {database files} {
  206.     list [catch {option read option.file2} msg] $msg
  207. } {1 {missing colon on line 2}}
  208.  
  209. catch {destroy .op1}
  210. catch {destroy .op2}
  211. concat {}
  212.